package com.hy.erp.inventory.service;

import java.util.HashMap ;
import java.util.List ;
import java.util.Map ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IProductCharacteristicDao;
import com.hy.erp.inventory.extjs.gxt.ui.client.data.BaseModel;
import com.hy.erp.inventory.pojo.ProductCharacteristic;
import com.hy.erp.inventory.pojo.interfaces.IProductCharacteristic;
import com.hy.erp.inventory.service.interfaces.IProductCharacteristicService;
/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-13；时间：上午11:18:05</li>
 * <li>类型名称：ProductCharacteristicService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */

@Name("productCharacteristicService")
@ Scope ( ScopeType.STATELESS )
@ Stateless
public class ProductCharacteristicService
											extends
											AbstractBusinessService < IProductCharacteristic >
																					implements
																					IProductCharacteristicService
{

	/**
	 * <ul>
	 * <li>开发作者：汤莉</li>
	 * <li>设计日期：2010-10-13；时间：上午11:18:02</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														6106938763375278411L ;

	public ProductCharacteristicService()
	{
		super ( );
	}
	
	@ Override
	public String[] addProductCharacteristic (
												Object[] objects )
	{
		if(objects==null)
		{
			return null;
		}
		else
		{
			IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
			ProductCharacteristic[] characteristics=new ProductCharacteristic[objects.length];
			for ( int i =
							0 ; i < objects.length ; i ++ )
			{
				ProductCharacteristic characteristic=( ProductCharacteristic ) objects[i];
				characteristics[i]=characteristic;
			}
			return dao.persist ( characteristics ) ;
		}
	}

	@ Override
	public Integer removeProductCharacteristic (
													String [ ] Ids )
	{
		if ( ( null == Ids )
			     || ( Ids.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
				return dao.remove ( Ids );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyProductCharacteristic (
													ProductCharacteristic characteristic )
	{
		if ( ( null == characteristic ) || ( null == characteristic.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
			IProductCharacteristic iProductCharacteristic= characteristic;
			
			if ( null == iProductCharacteristic )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( iProductCharacteristic )!=null) ;
		}
		
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public List < IProductCharacteristic > getProductById (
															String [ ] Id )
	{
		if((Id.length!=0)||(Id!=null))
		{
			IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
			return dao.findByIdentifier ( Id );
		}
		return null ;
	}

	@ Override
	public List < IProductCharacteristic > getAllProductCharacteristic ( )
	{
		IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
		return dao.find ( ) ;
	}

	@ Override
	public List < IProductCharacteristic > getProductCharacteristicByQueryName (
																					String queryName ,
																					String id )
	{


		if ( null ==queryName &&null == id )
		{
			return null ;
		}
		else
		{
			Map < String , Object > parameters =new HashMap < String , Object >();
			parameters.put ( "identifier" , id );
			
			IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
			return dao
			                .findByNamedQueryAndNamedParams(      queryName,
			                                                  parameters ) ;
	}
		
	
	}

	@ Override
	public List < IProductCharacteristic > getProductCharacteristicByQueryName (
																					String queryName ,
																					BaseModel baseModel )
	{



		if ( null ==queryName &&null == baseModel )
		{
			return null ;
		}
		else
		{
			String id=baseModel.get ( "identifier" );
			Map < String , Object > parameters =new HashMap < String , Object >();
			parameters.put ( "identifier" , id );
			IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
			return dao
			                .findByNamedQueryAndNamedParams(      queryName,
			                                                  parameters ) ;
	}
		
	
	
	}

	@ Override
	public String [ ] modifyProductCharacteristic (
													Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
			IProductCharacteristicDao dao=( IProductCharacteristicDao ) this.getDao ( IProductCharacteristic.class );
			ProductCharacteristic[] types=new ProductCharacteristic[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	ProductCharacteristic type=( ProductCharacteristic ) objects[i];
            	types[i]=type;
            }
			
			return dao.merge ( types );
		}
	}

}
